<h2>商品分类管理</h2>
<?php 
$this->menu = array(
	array('label'=>'添加分类', 'url'=>array('edit'), 'visible'=>Yii::app()->user->v('manage@GoodsCateEdit')),
);

$goods_cate_flags = EnumsModel::getEnums('goods_cate_flags');

function render_node($nodes, $goods_cate_flags){
	foreach ($nodes as $nid=>$node){
		echo '<tr class="row" parent="' . $node['parent'] . '">';
		echo CHtml::tag('td', array(), $node['name']);
		if(isset($node['goods_cate_flags']) && !empty($node['goods_cate_flags'])){
			//标识
			foreach ($node['goods_cate_flags'] as $i => $flag){
				$node['goods_cate_flags'][$i] = $goods_cate_flags[$flag];
			}
			echo CHtml::tag('td', array(), implode(', ', $node['goods_cate_flags']));
		}else{
			echo CHtml::tag('td', array(), '--');
		}
		echo CHtml::tag('td', array('class'=>'right'), $node['rank']);
		$link = array();
		$link[] = YHtml::link('预览', '/Manage/GoodsCate/View/' . $nid, array('visible'=>Yii::app()->user->v('manage@GoodsView')));
		$link[] = YHtml::link('商品列表', '/Manage/Goods/Admin/' . $nid, array('visible'=>Yii::app()->user->v('manage@GoodsAdmin')));
		$link[] = YHtml::link('添加商品', '/Manage/Goods/Edit/cate/' . $nid, array('visible'=>Yii::app()->user->v('manage@GoodsEdit')));
		if(Yii::app()->user->v("manage@GoodsCateEdit")){
			$link[] = YHtml::link('修改', '/Manage/GoodsCate/Edit/' . $nid);
			$link[] = YHtml::link('添加子分类', '/Manage/GoodsCate/Edit/parent/' . $nid);
		}
		$link[] = YHtml::link('删除', 'javascript:void(0)', array('visible'=>Yii::app()->user->v('manage@GoodsCateDelete'), 'onclick'=>'delete_cate()'));
		
		$link = array_filter($link);
		echo CHtml::tag('td', array(), implode(' | ', $link));
		echo '</tr>';
		if(isset($node['children'])){
			render_node($node['children'], $goods_cate_flags);
		}
	}
}
?>
<table class="y_table">
	<tr>
		<th>商品分类</th><th>标识</th><th>排序</th><th>操作</th>
	</tr>
	<?php render_node($tree, $goods_cate_flags);?>
</table>